package ch.ethz.inf.shop;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import ch.ethz.inf.shop.util.UserManagement;

/**
 * Servlet implementation class HomePage
 */
@WebServlet(description = "The home page of the project", urlPatterns = { "/HomePage" })
public final class HomeServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;
	public final static String SESSION_LOGGED_IN_USER = "loggedInUser";

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	@Override
	protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {

		final HttpSession session = request.getSession(true);
		session.setAttribute(SESSION_LOGGED_IN_USER, UserManagement.getCurrentlyLoggedInUser(session));

		this.getServletContext().getRequestDispatcher("/Home.jsp").forward(request, response);

	}

}
